package test.chat.client;

import test.chat.client.view.ChatView;
import test.chat.client.view.LoginView;
import test.chat.client.websockets.ChatCommandHandler;
import test.chat.client.websockets.ChatService;
import test.chat.client.websockets.CompletionHandler;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootLayoutPanel;

public class ChatApp implements EntryPoint {
    @Override
    public void onModuleLoad() {
        ChatService chatService = new ChatService();

        final ChatView chatView = new ChatView(chatService);

        final LoginView loginView = new LoginView(chatService);

        ChatCommandHandler commandHandler = new ChatCommandHandler(chatView);

        chatService.setCommandHandler(commandHandler);

        chatService.connect(new CompletionHandler() {
            @Override
            public void onComplete() {
                RootLayoutPanel.get().add(loginView);
            }
        });
    }
}
